﻿using Devonline.Core;

var n = 30;
Console.WriteLine($"Run Fibonacci test 10000 times for n={n} now!");

Console.WriteLine($"Run Fibonacci test 10000 times for n={n} loop test!");
var startTime = DateTime.Now;
for (int i = 0; i < 10000; i++)
{
    Fibonacci(30);
}

//Console.WriteLine((DateTime.Now - startTime).TotalMilliseconds);
Console.WriteLine(startTime.GetTimeDetail());

Console.WriteLine($"Run Fibonacci test 10000 times for n={n} paralla test!");
startTime = DateTime.Now;
Parallel.For(0, 10000, x => Fibonacci(30));
//Console.WriteLine((DateTime.Now - startTime).TotalMilliseconds);
Console.WriteLine(startTime.GetTimeDetail());

Console.WriteLine("Run Fibonacci test finished, please press any key to exit!");
Console.ReadKey();

static int Fibonacci(int n)
{
    if (n <= 1)
    {
        return 1;
    }

    return Fibonacci(n - 1) + Fibonacci(n - 2);
}